<?php

/**
 * @author Ermek
 * @copyright Hire-Experts LLC
 * @version Avatar 1.01
 */

defined('SE_PAGE') or exit();

include_once "./header_he_core.php";
include_once "./include/class_he_avatar.php";


if ( $page == 'user_editprofile_photo' )
{
	$page = 'user_he_avatar';
	
	if ( isset($_POST['task']) && $_POST['task'] == 'photo_for_crop' )
	{
		he_avatar::upload_photo('avatar_file');
	}
	
	if ( isset($_POST['task']) && $_POST['task'] == 'crop_avatar' )
	{
		he_avatar::crop_photo($_POST);
	}
	
	if ( isset($_POST['task']) && $_POST['task'] == 'no_crop_save' )
	{
		he_avatar::save_photo();
	}
	
	if ( isset($_POST['task']) && $_POST['task'] == 'choose_avatar' )
	{
		$he_avatar_id = isset($_POST['avatar_id']) ? (int)$_POST['avatar_id'] : 0;  
		he_avatar::choose_avatar($he_avatar_id);
	}
	
	//get avatar src
	$he_avatar_src = $url->url_userdir($user->user_info['user_id']) . 'he_avatar.jpg';

	$he_avatar_crop = 1;
	if ( file_exists($he_avatar_src) )
	{
		$he_avatar_info = getimagesize($he_avatar_src);
		$he_avatar_crop = 1;
		
		if ( $he_avatar_info[0] <= $user->level_info['level_photo_width'] 
			&& $he_avatar_info[1] <= $user->level_info['level_photo_height'] )
		{
			$he_avatar_crop = 0;	
		}
				
		$smarty->assign('crop_photo', $he_avatar_src);
		$smarty->assign('he_avatar_crop', $he_avatar_crop);
	}

	$smarty->assign('avatars', he_avatar::avatar_list());
	

	if ( is_a($smarty, 'SESmarty') )
	{
		$smarty->assign_hook('styles', './templates/he_avatar_styles.css');
		$smarty->assign_hook('scripts', './include/js/he_avatar.js');
	}
}

?>